
from commonrules import *
from level2rules import *
from level3rules import *
from mastergoal.common.move import *
from mastergoal.common.square import Square

class RuleEngine:
    
    level_rules = {1 : CommonRules, 2 : L2Rules, 3 : L3Rules}
    
    @staticmethod
    def valid_ball_movement(piece, destination, state):

        square = Square(*destination)
        move = BallMove(piece, square, state.player_with_ball)
        #print "Square " + str(square)
                
        response = RuleEngine.level_rules[state.level].valid_ball_move(state,move)

        #response = cls.valid_ball_move(state, move)        
        print CommonRules.desc_rules[response[1]]
        
        return (response[0], response[1], move)
        
    
    @staticmethod
    def valid_player_movement(piece, destination, state):
        
        square = Square(*destination)
        move = PlayerMove(piece, square) 
        #print "Square " + str(square)   
        
        #if state.level == 1:
        
        response = RuleEngine.level_rules[state.level].valid_player_move(state, move)
        
        
        print CommonRules.desc_rules[response[1]] 
        
        return (response[0], response[1], move)
            
    #valid_player_movement = staticmethod(valid_player_movement)